<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('SMS/call_sms_save')}" method="post">
        <ul>
            <if condition="$isSuperAdmin">
                <li><label>租户ID：</label><select name="siteID" title="请选择租户"></select></li>
                <else/>
                <li style="display: none;"><input type="hidden" name="siteID" value="{$loginData.siteID}"/></li>
            </if>
            <li>
                <label>短信服务器：</label>
                <select name="serverID"  title="请选择短信服务器" required></select>
            </li>
            <li>
                <label>任务策略：</label>
                <select name="taskStrategyID" title="请选择任务策略" required></select>
            </li>
            <li>
                <label>策略外呼时长(>=秒)：</label>
                <input type="checkbox" name="taskStrategyDurationEnable" value="1" /><input type="text" name="taskStrategyDuration" placeholder="策略外呼时长" value="{$data.taskStrategyDuration}" style="display: none;" />
            </li>
            <li>
                <label>分机按键：</label>
                <input type="checkbox" name="seatdtmfEnable" value="1" /><input type="text" name="seatdtmf" placeholder="分机按键" value="{$data.seatdtmf}" style="display: none;" />
            </li>
            <li>
                <label>短信内容：</label>
                <textarea cols="60" rows="3" name="message" placeholder="请输入短信内容">{$data.message}</textarea>
                <span></span>
            </li>
            <li>
                <label>短信签名：</label>
                <input type="text" name="sign" placeholder="请输入短信签名" value="{$data.sign}" readonly="readonly" />
            </li>
            <li>
                <label>状态：</label>
                <input type="radio" name="state" value="1" checked="checked" required />启用
                <input type="radio" name="state" value="0" required />停用
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="submit" value="保存"/><input type="button" value="关闭" class="btn-close-dialog"/></li>
        </ul>
        <input type='hidden' value='{$data.id}' name='id'/>
        <input type='hidden' value='strategy' name='exTags'/>
    </form>
</block>
<block name="body_after_block">
<script>
    $('input[name="state"][value="{$data.state}"]').prop('checked',true);
    $('input[name="taskStrategyDurationEnable"][value="{$data.taskStrategyDurationEnable}"]').prop('checked',true);
    $('input[name="seatdtmfEnable"][value="{$data.seatdtmfEnable}"]').prop('checked',true);
    ajax_load_options('select[name="siteID"]', '?s=XCall/Admin/get_admin_json.html', '选择租户', '{$data.siteID}','',afterSiteID);
    afterSiteID();
    function afterSiteID(){
        var val=$('select[name="siteID"]').val();
        if(!val){
            val='{$loginData.siteID}';
        }
        ajax_load_options('select[name="taskStrategyID"]', '?s=XCall/TaskStrategy/get_json/siteID/'+val+'.html', '请选择任务策略', '{$data.taskStrategyID}');
        ajax_load_options('select[name="serverID"]', '?s=XCall/SMS/get_server_json/siteID/'+val+'.html', '选择短信服务器', '{$data.serverID}');
    }
    $('select[name="siteID"]').change(function(){
        afterSiteID();
    })
    $('textarea[name="message"],input[name="sign"]').bind('blur keypress change', function () {
        var i = $('textarea[name="message"]').val().length+$('input[name="sign"]').val().length;
        $('#char-count').text(i);
    })
    $('input[name="taskStrategyDurationEnable"], input[name="seatdtmfEnable"]').change(function(){
        afterEnableCheckedbox(this);
    })
    afterEnableCheckedbox('input[name="taskStrategyDurationEnable"]');
    afterEnableCheckedbox('input[name="seatdtmfEnable"]');
    function afterEnableCheckedbox(selector){
        var $chk=$(selector);
        if($chk.prop('checked')){
            $chk.next().show();
        }else{
            $chk.next().hide();
        }
    }
    afterEnableCheckedbox();
</script>
</block>